package cn.edu.hunau.dao.impl;

import cn.edu.hunau.dao.IndexProductDao;
import cn.edu.hunau.pojo.IndexProduct;
import cn.edu.hunau.utils.DBUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author 苏佳
 * @Date 2022 12 04 16 37
 **/
public class IndexProductDaoImpl implements IndexProductDao {
    @Override
    public List<IndexProduct> queryByNews(String news) {
        String sql="select id,pid,name,price,pdesc,news,online,`order`,pimage from t_indexproduct where news=? and online='0' order by `order`";
        return DBUtils.query(sql, rs -> {
            List<IndexProduct> datas = new ArrayList<>();
            while(rs.next()){
                IndexProduct indexProduct = new IndexProduct();
                indexProduct.setId(rs.getInt("id"));
                indexProduct.setPid(rs.getInt("pid"));
                indexProduct.setName(rs.getString("name"));
                indexProduct.setPrice(rs.getDouble("price"));
                indexProduct.setDesc(rs.getString("pdesc"));
                indexProduct.setNews(rs.getString("news"));
                indexProduct.setOrder(rs.getInt("order"));
                indexProduct.setPimage(rs.getString("pimage"));
                indexProduct.setOnline(rs.getString("online"));
                datas.add(indexProduct);
            }
            return datas;
        },news);
    }
}
